package data

import (
	"fmt"

	"github.com/treelab/updatecolumn/models"
)

type DependentColumnsResult struct {
	DependentColumns []struct {
		Cells []models.Cell
	}
}

//GetDependentColumnCellsQueryString by ColumnID
func GetDependentColumnCellsQueryString(dependentColumnId string) string {
	return fmt.Sprintf(`
	{
		dependentColumns(func:uid(%s)) {
			cells: has_cell {
				uid
				rowId
			}
		}
	}`, dependentColumnId)
}

type GetColumnExistQueryResult struct {
	Workspaces []models.Workspace
}

// GetColumnExistQueryString create a query string to check column
func GetColumnExistQueryString(workspaceID, coreID, tableID, colID string) string {

	return fmt.Sprintf(`
		{
			workspaces(func:uid(%s)){
				cores: has_core @filter(uid(%s)) {
					tables: has_table @filter(uid(%s)) {
						columns: has_column @filter(uid(%s)) {
							uid
						}
					}
				}
			}
		}
	`, workspaceID, coreID, tableID, colID)

}

//GetColumnsByTableID return all columnIDs
func GetColumnsByTableIDQueryString(tableID string) string {
	return fmt.Sprintf(`
		tables(func:uid(%s)) {
			columns: has_column {
				uid
			}
		}
	`, tableID)
}

type ReferenceColumnsResult struct {
	ReferenceColumns []models.Column
}

//GetReferenceColumnCellsQuery for column query
func GetReferenceColumnCellsQuery(referenceColumnId string) string {
	return fmt.Sprintf(`
	{
		referenceColumns(func:uid(%s)){
			cells: has_cell {
				uid
				rowId
				foreignRows: has_foreign_row {
					uid
				}
			}
		}
	}
	`, referenceColumnId)
}

func GetAllColumnsByColumnsIDQueryString() string {

	return ""
}
